Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@thi.ng/strings

Package Overview
Dependencies
Maintainers
0
Versions
196
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thi.ng/strings

Various string formatting & utility functions

  • 3.8.10
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

@thi.ng/strings

npm version npm downloads Mastodon Follow

[!NOTE] This is one of 199 standalone projects, maintained as part of the @thi.ng/umbrella monorepo and anti-framework.

🚀 Please help me to work full-time on these projects by sponsoring me on GitHub. Thank you! ❤️

About

Various (~100) string formatting, word wrapping & utility functions, some higher-order, some memoized.

Partially based on Clojure version of thi.ng/strf.

General

  • defFormat / format
  • interpolate / interpolateKeys
  • escape / unescape
  • join / splice / split
  • repeat
  • stringify

Numeric formatters

  • currency / chf / eur / gpb / usd / yen
  • radix
  • int / intLocale
  • float / floatFixedWidth
  • maybeParseFloat / maybeParseInt
  • percent
  • uuid
  • vector
  • B8 / B16 / B32 - fixed size binary formatters
  • U8 / U16 / U24 / U32 / U64 - fixed size hex formatters
  • Z2 / Z3 / Z4 - fixed sized zero padded number formatters

Casing

  • lower / upper / capitalize
  • camel / kebab / snake / upperSnake

Slugify

  • slugify / slugifyGH

ANSI

  • isAnsi / isAnsiEnd / isAnsiStart
  • stripAnsi
  • lengthAnsi

Word wrapping

  • wordWrap / wordWrapLine / wordWrapLines
  • SPLIT_PLAIN / SPLIT_ANSI

Padding / wrapping

  • center
  • padLeft / padRight
  • truncate / truncateLeft / truncateRight
  • trim
  • wrap

Indentation

  • spacesToTabs / spacesToTabsLine
  • tabsToSpaces / tabsToSpacesLine

Char range presets / lookup tables

  • charRange
  • ALPHA / ALPHA_NUM / DIGITS / LOWER / UPPER / HEX
  • BOM / ESCAPES / ESCAPES_REV
  • WS / PUNCTUATION

Units

  • units
  • bits / bytes
  • grams
  • meters
  • seconds
  • ruler / grid

Miscellaneous

Status

STABLE - used in production

Search or submit any issues for this package

Installation

yarn add @thi.ng/strings

ESM import:

import * as str from "@thi.ng/strings";

Browser ESM import:

<script type="module" src="https://esm.run/@thi.ng/strings"></script>

JSDelivr documentation

For Node.js REPL:

const str = await import("@thi.ng/strings");

Package sizes (brotli'd, pre-treeshake): ESM: 5.52 KB

Dependencies

Note: @thi.ng/api is in most cases a type-only import (not used at runtime)

Usage examples

Eight projects in this repo's /examples directory are using this package:

ScreenshotDescriptionLive demoSource
ASCII art raymarching with thi.ng/shader-ast & thi.ng/text-canvasDemoSource
Large ASCII font text generator using @thi.ng/rdomDemoSource
Basic crypto-currency candle chart with multiple moving averages plotsDemoSource
Basic SPA example with atom-based UI routerDemoSource
Mastodon API feed reader with support for different media types, fullscreen media modal, HTML rewritingDemoSource
Generative audio synth offline renderer and WAV file exportDemoSource
rstream based spreadsheet w/ S-expression formula DSLDemoSource
XML/HTML/SVG to hiccup/JS conversionDemoSource

API

Generated API docs

Basic usage examples

import { defFormat, float, percent } from "@thi.ng/strings";

// create a custom string formatter
const fmt = defFormat([
    "Price: ",
    { usd: "$", gbp: "£", eur: "€" },
    float(2),
    " (",
    percent(2),
    " off)"
]);

// use format
fmt("usd", 1.2345, 0.5);
// Price: $1.23 (50.00% off)

fmt("eur", 1.2345, 0.25)
// Price: €1.23 (25.00% off)

Authors

If this project contributes to an academic publication, please cite it as:

@misc{thing-strings,
  title = "@thi.ng/strings",
  author = "Karsten Schmidt",
  note = "https://thi.ng/strings",
  year = 2015
}

License

© 2015 - 2024 Karsten Schmidt // Apache License 2.0

Keywords

FAQs

Package last updated on 10 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc